package avicit.bdp.dms.das.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class LogicExcelChangValue {
    private static final Logger logger = LoggerFactory.getLogger(LogicExcelChangValue.class);

    public static String changeType(String type, String length, String precision, Map<String, String> typeMap) {
        String newType = typeMap.get(type);
        if(StringUtils.isNotBlank(newType)){
            return newType;
        }else {
            if("文本".equals(type)&&StringUtils.isNotBlank(length)&&(!"-".equals(length))){
                if(Double.parseDouble(length) > 0){
                    return "字符串";
                }
            }
            if ("数值".equals(type)&&StringUtils.isNotBlank(length)&&(!"-".equals(length))){
                if(StringUtils.isBlank(precision)||(!"-".equals(precision))){
                    if(Double.parseDouble(length) > 11){
                        return "长整型";
                    }else {
                        return "整型";
                    }
                }
            }
        }
        return type;
    }

    public static Integer changeLength(String length) {
        if(StringUtils.isBlank(length)||("-".equals(length))){
            return null;
        }
        return Integer.valueOf((int) Double.parseDouble(length));
    }

    public static Integer changePrecision(String precision) {
        if(StringUtils.isBlank(precision)||("-".equals(precision))){
            return null;
        }
        return Integer.valueOf((int) Double.parseDouble(precision));
    }
}
